#!/usr/bin/env python
# coding: utf-8

# -----
# * 日期:week09
# * 课程:数据分析
# * Author：xiaohongzhou
# -----

# # 1. 数据获取

# In[1]:


url = 'https://api-c.liepin.com/api/com.liepin.searchfront4c.pc-search-job'


# * 请求方法：POST

# In[5]:


import requests,json


# In[37]:


payload = {
    "data":{
        "mainSearchPcConditionForm":{
            "city":"050020",
            "dq":"050020",
            "pubTime":"",
            "currentPage":"0",
            "pageSize":40,
            "key":"产品经理",
            "suggestTag":"",
            "workYearCode":"1$3",
            "compId":"",
            "compName":"",
            "compTag":"",
            "industry":"",
            "salary":"",
            "jobKind":"",
            "compScale":"",
            "compKind":"",
            "compStage":"",
            "eduLevel":""},
        "passThroughForm":{
            "scene":"condition",
            "skId":"z0bz071flsw02izwxhy5b8jue7eee7y8",
            "fkId":"8dvrtmhirdk3wdbhone8thq8dntxfy98",
            "ckId":"v36hi812yao8dawkkai2vuvv06nq2d0b",
            "suggest":None
        }
    }
}


# In[15]:


# headers = {
#     'User-Agent':"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36"
# }


# In[38]:


headers = {
    'Accept': 'application/json, text/plain, */*',
    'Accept-Encoding': 'gzip, deflate, br',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    'Content-Length': '490',
    'Content-Type': 'application/json;charset=UTF-8;',
    'Cookie': '__gc_id=0baa2ddaa7774d8fba2b9c2c3d8ba166; __uuid=1670205465393.76; XSRF-TOKEN=jFbKBscGQu-Qqzq9Ues4pQ; _ga=GA1.1.918067290.1681902564; __tlog=1681902565833.98%7C00000000%7C00000000%7C00000000%7C00000000; Hm_lvt_a2647413544f5a04f00da7eee0d5e200=1681902572; __session_seq=21; __uv_seq=21; Hm_lpvt_a2647413544f5a04f00da7eee0d5e200=1681904656; _ga_54YTJKWN86=GS1.1.1681906862.2.0.1681906862.0.0.0',
    'Host': 'apic.liepin.com',
    'Origin': 'https://www.liepin.com',
    'Pragma': 'no-cache',
    'Referer': 'https://www.liepin.com/',
    'sec-ch-ua': '"Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': 'Windows"',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-site',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36',
    'X-Client-Type': 'web',
    'X-Fscp-Bi-Stat': '{"location": "https://www.liepin.com/zhaopin/?city=050020&dq=050020&pubTime=&currentPage=0&pageSize=40&key=%E4%BA%A7%E5%93%81%E7%BB%8F%E7%90%86&suggestTag=&workYearCode=1$3&compId=&compName=&compTag=&industry=&salary=&jobKind=&compScale=&compKind=&compStage=&eduLevel=&otherCity=&ckId=8dvrtmhirdk3wdbhone8thq8dntxfy98&scene=condition&skId=z0bz071flsw02izwxhy5b8jue7eee7y8&fkId=8dvrtmhirdk3wdbhone8thq8dntxfy98&sfrom=search_job_pc&suggestId="',
    'X-Fscp-Fe-Version': '',
    'X-Fscp-Std-Info': '{"client_id": "40108"}',
    'X-Fscp-Trace-Id': 'cf1da507-19a3-480f-b7e5-c649f6f5432c',
    'X-Fscp-Version': '1.1',
    'X-Requested-With': 'XMLHttpRequest',
    'X-XSRF-TOKEN': 'jFbKBscGQu-Qqzq9Ues4pQ'
}


# * json.dumps   把python当中的字典 转换成 json

# In[39]:


r = requests.post(url,data=json.dumps(payload),headers=headers)


# In[40]:


r.request.headers


# In[35]:


r.status_code


# In[ ]:


data_liepin = r.json()
data_liepin


# In[42]:


import pandas as pd 


# In[56]:


pd.json_normalize(data_liepin['data']['data']['jobCardList'])


# In[ ]:




